package com.meizu.asum.richtextsdk.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;

/**
 * 通用的Viewpager适配器
 * 
 * @author Asum
 *
 */
public class ViewPagerAdapter extends PagerAdapter {
	private ArrayList<View> childs;

	public ViewPagerAdapter(ArrayList<View> childs) {
		this.childs = childs;
	}

	public boolean isViewFromObject(View arg0, Object arg1) {
		return arg0 == arg1;
	}

	public void clear() {
		childs.clear();
		childs = null;
	}

	public int getCount() {
		return childs.size();
	}

	public void destroyItem(ViewGroup container, int position, Object object) {
		container.removeView((View) childs.get(position));
	}

	public int getItemPosition(Object object) {
		return super.getItemPosition(object);
	}

	public Object instantiateItem(ViewGroup container, int position) {
		container.addView((View) childs.get(position));
		return childs.get(position);
	}
}